/*    */ package net.sourceforge.appgen.generator;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.FileWriter;
/*    */ import java.io.Writer;
/*    */ import net.sourceforge.appgen.model.ConnectionInformation;
/*    */ import net.sourceforge.appgen.model.Entity;
/*    */ import net.sourceforge.appgen.model.GenerationInformation;
/*    */ import org.apache.velocity.Template;
/*    */ import org.apache.velocity.VelocityContext;
/*    */ import org.apache.velocity.app.Velocity;
/*    */ 
/*    */ public class JdbcPropertiesFileGenerator extends OnceFileGenerator
/*    */ {
/*    */   public static final String TEMPLATE = "jdbcProperties.vm";
/*    */   private ConnectionInformation connectionInformation;
/*    */ 
/*    */   public JdbcPropertiesFileGenerator(GenerationInformation generationInformation, ConnectionInformation connectionInformation)
/*    */   {
/* 41 */     super(generationInformation);
/*    */ 
/* 43 */     this.connectionInformation = connectionInformation;
/*    */   }
/*    */ 
/*    */   public File generateFile(Entity entity, String template, File file) throws Exception
/*    */   {
/* 48 */     Velocity.init(this.properties);
/*    */ 
/* 50 */     Template modelTemplate = Velocity.getTemplate(template);
/*    */ 
/* 52 */     VelocityContext context = new VelocityContext();
/* 53 */     context.put("connectionInformation", this.connectionInformation);
/* 54 */     context.put("packageName", this.packageName);
/*    */ 
/* 56 */     Writer writer = null;
/*    */     try
/*    */     {
/* 59 */       writer = new FileWriter(file);
/*    */ 
/* 61 */       modelTemplate.merge(context, writer);
/*    */     } catch (Exception e) {
/* 63 */       throw e;
/*    */     } finally {
/* 65 */       if (writer != null)
/*    */         try {
/* 67 */           writer.close();
/*    */         }
/*    */         catch (Exception localException1)
/*    */         {
/*    */         }
/*    */     }
/* 73 */     return file;
/*    */   }
/*    */ 
/*    */   public File generate(Entity entity) throws Exception
/*    */   {
/* 78 */     if (!this.aleradyGenerate) {
/* 79 */       this.aleradyGenerate = true;
/*    */ 
/* 81 */       return generateFile(entity, getTemplate(), getFile(entity));
/*    */     }
/*    */ 
/* 84 */     return null;
/*    */   }
/*    */ 
/*    */   public File getFile(Entity entity)
/*    */   {
/* 89 */     return new File(getDirectory(), "jdbc.properties");
/*    */   }
/*    */ 
/*    */   public File getDirectory()
/*    */   {
/* 94 */     return new File(this.outputDir.getPath() + File.separator + "WebContent" + File.separator + "WEB-INF" + File.separator + "properties");
/*    */   }
/*    */ 
/*    */   public String getTemplate()
/*    */   {
/* 99 */     return "jdbcProperties.vm";
/*    */   }
/*    */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.generator.JdbcPropertiesFileGenerator
 * JD-Core Version:    0.6.0
 */